package com.sdkj.action.log;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.sdkj.Entity.admin.AdminUser;
import com.sdkj.action.base.BaseAction;
import com.sdkj.log.OperationLog;
import com.sdkj.service.log.IOperationLogService;
import com.sdkj.utils.CommonUtils;
import com.sdkj.utils.PageBean;

@Controller
@Scope("prototype")
public class OperationLogAction extends	BaseAction<OperationLog, IOperationLogService> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * 查询某用户的某种操作日志
	 * @throws SQLException
	 */
	public void list() throws SQLException{
		String op=getRequest().getParameter("op");
		AdminUser user=(AdminUser) getSession().getAttribute("curuser");
		String uid=user.getUuid();
		String hql=" from OperationLog where uid=:uid and operation like :op order by createTime desc";
		Map<String,Object>params=new HashMap<String,Object>();
		params.put("uid", uid);
		params.put("op", op);
		int s=service.count("select count(*) "+hql, params); 
		PageBean pb=new PageBean(page, s, rows);
		List<OperationLog> data=service.find(hql, params, page, rows);
		JSONObject res=new JSONObject();
		res.put(RES_CODE, 100);
		res.put(RES_MSG, "查询成功");
		res.put("data", data);
		res.put("pagebean", pb);
		CommonUtils.writeJson(res);
	}
	 
	public void del() throws SQLException{
		boolean flag=service.deleteIds(ids);
		JSONObject res=new JSONObject();
		if(flag){
			res.put(RES_CODE, 100);
			res.put(RES_MSG, "删除数据成功");
		}else{
			res.put(RES_CODE, -100);
			res.put(RES_MSG, "删除数据失败");
		}
		CommonUtils.writeJson(res);
	}

}
